<!-- 优势学科 -->
<template>
	<view id="subjectPage">
		<view class="content">
			<view class="right" v-if="collegeData && collegeData.length">
				<!-- {{collegeData}} -->
				<view class="item" v-for="(item,index) in collegeData" @click="handleJump(item)" :key="index">
					<text class="majorName" v-if="type==1 || type == 2 "><text
							style="margin-right: 20rpx;">{{item.subjectCode}}</text> {{ item.title}} </text>
					<text class="majorName" v-else><text style="margin-right: 20rpx;">{{item.majorCode}}</text>
						{{ item.majorName}} </text>
					<uni-icons class="icon-right" type="forward" v-if="type >= 3" color="#333" size="20"></uni-icons>
				</view>
			</view>
		</view>
		<view>
			<uni-nodata></uni-nodata>
		</view>
	</view>
</template>

<script>
	import {
		getAdvantages,
		majorDistributionList
	} from '@/api/toolbox.js'
	export default {
		data() {
			return {
				collegeData: [],
				type: '', // 1、优势学科，2、优势一级学科，3、优势专业，4、学院专业，5、学科专业
				queryParams: {
					pageNum: 1,
					pageSize: 999,
					reasonable: true,
					schoolCode: '',
					year: '2023'
				},

				searchParam: {
					collegeCode: "",
					major: "",
					pageNum: 1,
					pageSize: 999,
					reasonable: true,
					schoolCode: "",
					star: "",
					subjectCode: "",
					year: new Date().getFullYear()
				},
				total: 0,
			}
		},
		onLoad(options) {
			this.type = options.type;
			let navTitle = '优势学科';
			if (this.type == 2) {
				navTitle = '优势一级学科'
			} else if (this.type == 3) {
				navTitle = '优势专业'
			} else if (this.type == 4) {
				this.searchParam.collegeCode = options.code;
				navTitle = options.title + '开设的专业'
			} else if (this.type == 5) {
				this.searchParam.subjectCode = options.code;
				navTitle = options.title + '学科门类下的专业'
			}
			uni.setNavigationBarTitle({
				title: navTitle
			})
			this.searchParam.schoolCode = uni.getStorageSync('schoolCode');
			this.queryParams.schoolCode = uni.getStorageSync('schoolCode');
			this.queryParams.year = uni.getStorageSync('yearS');
			this.getList();
		},
		methods: {
			getList() {
				this.collegeData = [];
				if (this.type >= 4) {
					majorDistributionList(this.searchParam).then(res => {
						this.collegeData = res.data.rows;
					})
				} else {
					getAdvantages({
						schoolCode: this.queryParams.schoolCode,
						year: this.queryParams.year
					}).then(res => {
						if (this.type == 1) {
							this.collegeData = res.data[0].advantageSubjectCountList;
						}
						if (this.type == 2) {
							this.collegeData = res.data[0].advantageSubjectOneCountList;
						}
						if (this.type == 3) {
							this.collegeData = res.data[0].advantageMajorCountList;
						}
					})
				}
			},

			handleJump(item) {
				if (this.type >= 3) {
					let items = {
						"collegeCode": item.collegeCode, //"023"
						"majorCode": item.majorCode, //"010101"
						"schoolCode": item.schoolCode, //"10001"
					}
					uni.navigateTo({
						url: '/pages/toolbox/chooseMajor/major/majorDetail?items=' + JSON.stringify(items)
					})

				}

			},
		}
	}
</script>


<style lang="less" scoped>
	#subjectPage {
		height: 100%;
		display: flex;
		flex-direction: column;

		.table-title {
			width: 100%;
			display: flex;
			align-items: center;
			// justify-content: space-around;
			color: #333333;
			font-weight: 700;
			font-style: normal;
			font-size: 14px;
			height: 80rpx;
			background: rgba(250, 250, 250, 1);
			position: fixed;

			.table-title-item1 {
				width: 150rpx;
				text-align: center;
			}

			.table-title-item2 {
				width: 240rpx;
				text-align: center;
			}

			.table-title-item3 {
				width: 58%;
				text-align: center;
			}
		}

		.content {
			flex-grow: 1;
			display: flex;
			overflow: hidden;
			// padding-bottom: calc(180rpx + env(safe-area-inset-bottom));
			padding-bottom: 20rpx;
			// height: 100%;
			margin-top: 20rpx;

			.right {
				overflow: scroll;
				flex-grow: 1;
				background: #fff;
				padding-bottom: env(safe-area-inset-bottom);
				// margin-left: 150px;
				// margin-left: 372rpx;
				min-height: 100vh;

				// position: fixed;
				// .goods {
				.item {
					display: flex;
					// flex-direction: column;
					align-items: center;
					justify-content: space-between;
					padding-left: 20rpx;
					min-height: 100rpx;
					// line-height: 100rpx;
					border-bottom: 1px solid #f9fafb;
					margin: 0 40rpx 0 20rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;

					.majorName {
						width: auto;
						max-width: 560rpx;
						font-size: 14px;
						color: #555555;
					}

					.icon-right {
						width: 8rpx;
						height: 16rpx;
					}

					.sort-style {
						font-size: 13px;
						font-weight: 400;
						background: rgba(0, 0, 0, 0.7);
						color: #ffffff;
						border-bottom-right-radius: 20px;
						position: absolute;
						left: 0px;
						margin-top: -50px;
					}
				}

				// }
			}

			.item-active {
				color: #0BB976 !important;

				.sort-style {
					background: #0BB976;
				}
			}

		}
	}
	
	.empty{
		width: 600rpx;
		height: 600rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		margin: 0 auto;
	}
</style>